package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizOperationLog;
import com.member.shop.domain.SysBizPop;
import com.member.shop.service.ISysBizPopService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【弹屏管理】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2025-01-08
 **/
@RestController
@RequestMapping("/shop/pop")
public class SysBizPopController extends BaseController {
    @Resource
    private ISysBizPopService sysBizPopService;

    private void setTenantId(SysBizPop sysBizPop) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizPop.setTenantId(tenantId);
        }
    }

    /**
     * 查询弹屏管理列表
     */
    @PreAuthorize("@ss.hasPermi('shop:pop:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizPop sysBizPop) {
        startPage();
        setTenantId(sysBizPop);
        List<SysBizPop> list = sysBizPopService.selectSysBizPopList(sysBizPop);
        return getDataTable(list);
    }

    /**
     * 导出弹屏管理列表
     */
    @PreAuthorize("@ss.hasPermi('shop:pop:export')")
    @Log(title = "弹屏管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizPop sysBizPop) {
        setTenantId(sysBizPop);
        List<SysBizPop> list = sysBizPopService.selectSysBizPopList(sysBizPop);
        ExcelUtil<SysBizPop> util = new ExcelUtil<SysBizPop>(SysBizPop.class);
        util.exportExcel(response, list, "弹屏管理数据");
    }

    /**
     * 获取弹屏管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:pop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizPopService.selectSysBizPopById(id));
    }

    /**
     * 新增弹屏管理
     */
    @PreAuthorize("@ss.hasPermi('shop:pop:add')")
    @Log(title = "弹屏管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizPop sysBizPop) {
        return toAjax(sysBizPopService.insertSysBizPop(sysBizPop));
    }

    /**
     * 修改弹屏管理
     */
    @PreAuthorize("@ss.hasPermi('shop:pop:edit')")
    @Log(title = "弹屏管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizPop sysBizPop) {
        return toAjax(sysBizPopService.updateSysBizPop(sysBizPop));
    }

    /**
     * 删除弹屏管理
     */
    @PreAuthorize("@ss.hasPermi('shop:pop:remove')")
    @Log(title = "弹屏管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizPopService.deleteSysBizPopByIds(ids));
    }
}
